<?php
require_once __DIR__ . '/SpiderModel.php';

class DltDataModel
{
    protected $dataRoot = '';
    public function __construct()
    {
        $this->dataRoot = dirname(__DIR__) . '/data/dlt/';
        if (!file_exists($this->dataRoot)) {
            mkdir($this->dataRoot, 0777, true);
        }
    }

    public function datasource($isForce = false)
    {
        if ($isForce) {
            (new SpiderModel())->fetchDlt(false);
        }
        $filename = $this->dataRoot . 'data-all.json';
        if (!file_exists($filename)) {
            return message(null, '数据不存在', 500);
        }
        return message(json_decode(file_get_contents($filename), true));
    }
}
